<!DOCTYPE html>
<html>
<head>
    <title>JS对象测试</title>
    <meta charset="utf-8"/>
    <script>
        //第1种写法
        function Circle(r) {
            this.r = r;
        }
        Circle.PI = 3.14159;
        Circle.prototype.area = function() {
            return Circle.PI * this.r * this.r;
        }

        var c = new Circle(1.0);
        alert("第1种写法:" + c.area());

        //第2种写法
        var Circle = function() {
            var obj = new Object();
            obj.PI = 3.14159;

            obj.area = function( r ) {
                return this.PI * r * r;
            }
            return obj;
        }

        var c = new Circle();
        alert("第2种写法:" + c.area( 1.0 ) );


        //第3种写法
        var Circle = new Object();
        Circle.PI = 3.14159;
        Circle.Area = function( r ) {
            return this.PI * r * r;
        }
        alert("第3种写法:" +  Circle.Area( 1.0 ) );

        //第4种写法
        var Circle={
            "PI":3.14159,
            "area":function(r){
                return this.PI * r * r;
            }
        };
        alert("第4种写法:" +  Circle.area(1.0) );

        //第5种写法
        var Circle = new Function("this.PI = 3.14159;this.area = function( r ) {return r*r*this.PI;}");
        alert( "第5种写法:" + (new Circle()).area(1.0) );

    </script>
</head>
<body>

</body>
</html>